money = int(input("输入你的工资："))
product_list = [["iphone",5800],["alex",250],["bus",1000],["book",40]]
shopping_list = []
while True:
    print("product  list".center(20,"-"))
    for i,v in enumerate(product_list):
        print("%s:%s\t%s"%(i,v[0],v[1]))
    choose_shopping = input("选择要购买的商品,q健退出：")
    if choose_shopping.isdigit():
        choose_shopping = int(choose_shopping)
        if choose_shopping < len(product_list) >= 0:
            goods = product_list[choose_shopping]
            if goods[1] <= money:
                money -= goods[1]
                shopping_list.append(goods)
                print("%s 物品已加入购物车，您的余额为%s"%(goods[0],money))
            else:
                print("您的余额还剩%s，不能购买%s，请选择其他商品："%(money,goods[0]))
        else:
            print("输入的商品不存在，请重新输入")
    elif choose_shopping == "q":
        total_money = 0
        print("您的购物清单".center(20,"-"))
        print("已购买的商品")
        for i in shopping_list:
            print(i)
            total_money += i[1]
        print("总共消费：",total_money)
        print("您的余额：",money)
        break

